<?php

1->pom
<dependency>
   <groupId>com.thoughtworks.xstream</groupId>
   <artifactId>xstream</artifactId>
   <version>1.4.10</version>
</dependency>


2->核心code
XStream xstream = new XStream(new StaxDriver());
// 上面代码段中关键代码是xstream.ignoreUnknownElements();。加上这句代码，经测试无论合作方报文中是多节点还是少节点，我方解析的时候都不会报错。
xstream.ignoreUnknownElements();
xstream.alias("person", Person.class);
Person person = (Person) xstream.fromXML(xmlasjd);



3->原始xml
<?xml version="1.0" ?>
<person name="admin管理员">
    <sex>男</sex>
    <resetage>25</resetage>
    <home-address>
        <country>中国</country>
        <province>安徽</province>
        <city>宿州</city>
        <county>萧县</county>
    </home-address>
    <home-address>
        <country>中国</country>
        <province>上海</province>
        <county/>
    </home-address>
</person>


4->实体类
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
@XStreamAlias("person")
public class Person {
    //姓名
    @XStreamAsAttribute
    private String name;
    //性别
    private String sex;
    //年龄
    @XStreamAlias("resetage")
    private int age;
    //地址
    @XStreamImplicit(itemFieldName="home-address")
    private List<Address> Address;

    @XStreamOmitField
    private String invalidField; //此字段不会被序列化到xml中

}


5->注解说明
@XStreamAlias("person") 别名注解	类,字段
@XStreamImplicit (忽略集合名字	集合字段)
@XStreamAsAttribute (将字段转换成节点属性	字段)
@XStreamOmitField (忽略属性	字段)






.
